#include "debug.h"
#include "../DDIC/AllDDIC.h"
#include "usbd_cdc_core.h"
//********************************************************************************************   
//1:Flash ID Read;
void ILI7835_Enable_Flash_Control_and_SPI_Flash_En(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{

		//u8 buffer1[3];
	u8 Read_Flash_ID_1st_byte_Set[18]={//0xFF,0x78,0x35,0x06,
								 0xA2,0x00,0x9E,0x9F,
								 0x9E,0x00,0x9E,0x00,0x9E,0x00,
								 0xA1,0x00,0xA2,0xC0};
	u8 Read_Flash_ID_2nd_byte_Set[18]={//0xFF,0x78,0x35,0x06,
								 0xA2,0x00,0x9E,0x9F,
								 0x9E,0x00,0x9E,0x00,0x9E,0x00,
								 0xA1,0x01,0xA2,0xC0};
	u8 Read_Flash_ID_3rd_byte_Set[18]={//0xFF,0x78,0x35,0x06,
								 0xA2,0x00,0x9E,0x9F,
								 0x9E,0x00,0x9E,0x00,0x9E,0x00,
								 0xA1,0x02,0xA2,0xC0};
//	u8 Read_Flash_CS_High_Set[2]={0xA2,0xC0};
	
	{
		u8 buffer1[6];
		SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
		delay_ms(15);
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x06;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		for(i=0;i<sizeof(Read_Flash_ID_1st_byte_Set);i++)
		{
			buffer1[0] = 0x02;
			buffer1[1] = Read_Flash_ID_1st_byte_Set[i];
			buffer1[2] = Read_Flash_ID_1st_byte_Set[i+1];
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
			i+=1;
		}
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
		SSD2828_W_Reg(SigMode,channel,0xBC,0x0002);	
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0001); //return package 		 	                          
		buffer1[0] = 0x01;
		buffer1[1] = 0xBE;
		//buffer1[2] = 0x01;		
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(15);
		buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);     //返回第一个字节； C8  

		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15);
		for(i=0;i<sizeof(Read_Flash_ID_2nd_byte_Set);i++)
		{
			buffer1[0] = 0x02;
			buffer1[1] = Read_Flash_ID_2nd_byte_Set[i];
			buffer1[2] = Read_Flash_ID_2nd_byte_Set[i+1];
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(5);
			i+=1;
		}
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
		SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);	
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0001); //return package 		 	                          
		buffer1[0] = 0x01;
		buffer1[1] = 0xBE;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(15);
		buffer[4+1]=SSD2828_R_Reg(SigMode,channel,0xFF);     //返回第二个字节；60
		
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15);
		for(i=0;i<sizeof(Read_Flash_ID_3rd_byte_Set);i++)
		{
			buffer1[0] = 0x02;
			buffer1[1] = Read_Flash_ID_3rd_byte_Set[i];
			buffer1[2] = Read_Flash_ID_3rd_byte_Set[i+1];
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(5);
			i+=1;
		}
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
		SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);	
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0001); //return package 		 	                          
		buffer1[0] = 0x01;
		buffer1[1] = 0xBE;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(15);
		buffer[4+2]=SSD2828_R_Reg(SigMode,channel,0xFF);     //返回第二个字节；15
		

		buffer[0] = 0x2F;
		buffer[1] = 0x01;
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);  
	}
}

//2:Flash Setting &De-Mura Ram Enable;
void ILI7835_FlashSetting(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[5];
	u8 ILI7835_FlashSetting_Code[18]={	//0xFF,0x78,0x35,0x06,
										0x1A,0x41,0xB1,0x10,			//Set Flash Timing
										0xAA,0x1F,0xAB,0xFD,0xAC,0xE4,	//Set Flash size:16Mbit
										0xAA,0x0F,0xAB,0xFF,0xAC,0xC4,	//Set Flash size:8Mbit
										0xA6,0x48						//Set Flash Type GD25LQ16C
										//0xFF,0x78,0x35,0x03
										//0xD2,0x0C
									};
			
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);//LP_B7_Data
	delay_ms(15);	
		
	{
		//SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);//切Page_06
		//delay_ms(15);
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x0A;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x90;
			buffer1[2]=0x9A;        //De-Mura OFF
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x03;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		{
			buffer1[0]=0x02;
			buffer1[1]=0xD2;
			buffer1[2]=0x0C;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		//De-Mura RAM Enable;
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x19;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		{
			buffer1[0]=0x02;
			buffer1[1]=0x11;
			buffer1[2]=0x0A;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		buffer[0] = 0x2F;
		buffer[1] = 0x02;		
		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);    
	}	

}

                                    
//3.Flash Data Load
void ILI7835_Flash_Demura_Data_Load(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	//Page0 2C
	u8 buffer1[5];	
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);	
	{
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		{
			buffer1[0]=0x01;
			buffer1[1]=0x2C;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		buffer[0] = 0x2F;
		buffer[1] = 0x03;		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);  
	}  
}
//4:Flash RAM Disable;
void ILI7835_Flash_RAM_Disable(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	//ff,78,35,19 11,02
	u8 buffer1[5];
			
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);	
		
	{
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x19;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		{
			buffer1[0]=0x02;
			buffer1[1]=0x11;
			buffer1[2]=0x02;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		buffer[0] = 0x2F;
		buffer[1] = 0x04;		
		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);    
	}	

}

                                    
//5.Flash Erase
void ILI7835_Flash_Erase(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	//FF,78,35,6;A2,00;9E,06;delay_ms(1);A2,C0;delay_ms(10);A2,00;9E,60;delay_ms(1);A2,C0;
	u8 buffer1[5];			
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);	
		
	{
		
		{	
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x06;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA2;
			buffer1[2]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
				{
			buffer1[0]=0x02;
			buffer1[1]=0x9E;
			buffer1[2]=0x06;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA2;
			buffer1[2]=0xC0;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(10);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA2;
			buffer1[2]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x9E;
			buffer1[2]=0x60;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA2;
			buffer1[2]=0xC0;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		delay_ms(10000);//擦除需要延迟5s左右，视Flash情况而定；
		//增加返回数据，确定是否擦除
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA2;
			buffer1[2]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x9E;
			buffer1[2]=0x0b;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x9E;
			buffer1[2]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
				{
			buffer1[0]=0x02;
			buffer1[1]=0x9E;
			buffer1[2]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
				{
			buffer1[0]=0x02;
			buffer1[1]=0x9E;
			buffer1[2]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA1;
			buffer1[2]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA2;
			buffer1[2]=0xC0;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(100);		
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0xBE;
			buffer1[2]=0x01;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);		
		}
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
		SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);	
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  
		do
		{                        
				buffer1[0] = 0x01;
				buffer1[1] = 0xBE;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
				delay_ms(6);
				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);   
				delay_ms(100);
		}while((buffer[4]&0xFF)!=0xFF);
		
		buffer[0] = 0x2F;
		buffer[1] = 0x05;		
		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);
	}
	
}
                               


//6.Flash Write De-Mura Data
void ILI7835_Flash_Write_Demura_Data(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[5];
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);	
		
	{
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x06;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA2;
			buffer1[2]=0x90;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		
		{
			buffer1[0]=0x02;
			buffer1[1]=0xA4;
			buffer1[2]=0x55;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(5);		
		}
		delay_ms(10000);
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); //LP_B7_Data|0x0080
		SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);	
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0001); //return package 		 	                          
		do
		{                        
				buffer1[0] = 0x01;
				buffer1[1] = 0xBD;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
				delay_ms(6);
				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);   
				delay_ms(100);
		}while((buffer[4]&0x88)!=0x88);
		
		buffer[0] = 0x2F;
		buffer[1] = 0x06;			
			
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);	
	}
		
}
//7.Re-Load De-Mura.
void ILI7835_Flash_Reload_Demura_Data(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[5];
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);
	{
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x01;
			buffer1[1]=0x10;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		delay_ms(125);
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x06;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x45;
			buffer1[2]=0x4C;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x0a;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x90;
			buffer1[2]=0x9B;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0] = 0x01;
			buffer1[1] = 0x11;
			SSD2828_W_Array(SigMode,channel,buffer1,0); 
		}
			delay_ms(120);
		
		buffer[0] = 0x2F;
		buffer[1] = 0x07;				

		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);			 		
	}	
		
}
//8.CRC Check
void ILI7835_Flash_Demura_Data_CRC(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	//IC Reload flash data CRC page6_B7/B8
	//Calc_CRC_Page6_BB/BC
	u8 buffer1[5];
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);	
		
	{
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x06;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}		
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); //
		SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);	
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0001); //return package 		 	                          
		buffer1[0] = 0x01;
		buffer1[1] = 0xB7;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(3);
		buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);     //返回；CRC
		buffer1[0] = 0x01;
		buffer1[1] = 0xB8;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(3);
		buffer[5]=SSD2828_R_Reg(SigMode,channel,0xFF);
		buffer1[0] = 0x01;
		buffer1[1] = 0xBB;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(3);
		buffer[6]=SSD2828_R_Reg(SigMode,channel,0xFF);     //返回；CRC
		buffer1[0] = 0x01;
		buffer1[1] = 0xBC;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(3);
		buffer[7]=SSD2828_R_Reg(SigMode,channel,0xFF);
		
		buffer[0] = 0x2F;
		buffer[1] = 0x08;			
			
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);   
	}
}
//9.De-Mura Function On
void ILI7835_Demura_Function_ON(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	//PageA 90,93
	u8 buffer1[5];
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);
	{
//		{
//			buffer1[0]=0x04;
//			buffer1[1]=0xFF;
//			buffer1[2]=0x78;
//			buffer1[3]=0x35;
//			buffer1[4]=0x00;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		{
//			buffer1[0]=0x01;
//			buffer1[1]=0x10;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		delay_ms(125);
//		{
//			buffer1[0]=0x04;
//			buffer1[1]=0xFF;
//			buffer1[2]=0x78;
//			buffer1[3]=0x35;
//			buffer1[4]=0x06;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		{
//			buffer1[0]=0x02;
//			buffer1[1]=0x45;
//			buffer1[2]=0x4C;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x0a;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x90;
			buffer1[2]=0x9B;//De-Mura On
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
//		{
//			buffer1[0]=0x04;
//			buffer1[1]=0xFF;
//			buffer1[2]=0x78;
//			buffer1[3]=0x35;
//			buffer1[4]=0x00;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		{
//			buffer1[0] = 0x01;
//			buffer1[1] = 0x11;
//			SSD2828_W_Array(SigMode,channel,buffer1,0); 
//		}
		buffer[0] = 0x2F;
		buffer[1] = 0x09;		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);  
	}  
}

//A.De-Mura Function Off
void ILI7835_Demura_Function_OFF(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[5];
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
	delay_ms(15);
	{
//		{
//			buffer1[0]=0x04;
//			buffer1[1]=0xFF;
//			buffer1[2]=0x78;
//			buffer1[3]=0x35;
//			buffer1[4]=0x00;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		{
//			buffer1[0]=0x01;
//			buffer1[1]=0x10;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		delay_ms(125);
//		{
//			buffer1[0]=0x04;
//			buffer1[1]=0xFF;
//			buffer1[2]=0x78;
//			buffer1[3]=0x35;
//			buffer1[4]=0x06;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		{
//			buffer1[0]=0x02;
//			buffer1[1]=0x45;
//			buffer1[2]=0x4C;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
		{
			buffer1[0]=0x04;
			buffer1[1]=0xFF;
			buffer1[2]=0x78;
			buffer1[3]=0x35;
			buffer1[4]=0x0a;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
		{
			buffer1[0]=0x02;
			buffer1[1]=0x90;
			buffer1[2]=0x9A; //De-Mura OFF
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(3);
		}
//		{
//			buffer1[0]=0x04;
//			buffer1[1]=0xFF;
//			buffer1[2]=0x78;
//			buffer1[3]=0x35;
//			buffer1[4]=0x00;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(3);
//		}
//		{
//			buffer1[0] = 0x01;
//			buffer1[1] = 0x11;
//			SSD2828_W_Array(SigMode,channel,buffer1,0); 
//		}
		buffer[0] = 0x2F;
		buffer[1] = 0x0A;		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);  
	}       
}

void ProcessForDmuR1F( USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)
{	
	switch(USB_Rx_Buffer[1])
	{
			case 0x01:                                      // 
					ILI7835_Enable_Flash_Control_and_SPI_Flash_En(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
					//ILI7835_Inter_Demura_Ram(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x02:                                      // 
					ILI7835_FlashSetting(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
					//ILI7835_Exit_Demura_Ram(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;						 
			case 0x03:                                      // 
					ILI7835_Flash_Demura_Data_Load(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x04:                                      // 
					ILI7835_Flash_RAM_Disable(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;												
			case 0x05:                                      // 
					ILI7835_Flash_Erase(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;
			case 0x06:                                      // 
					ILI7835_Flash_Write_Demura_Data(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);				
			break;
			case 0x07:                                      // 
					ILI7835_Flash_Reload_Demura_Data(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;
			case 0x08:                                      // 
					ILI7835_Flash_Demura_Data_CRC(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;			
			case 0x09:                                      // 
					ILI7835_Demura_Function_ON(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x0A:                                      // 
					ILI7835_Demura_Function_OFF(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;													
			
			default:
				break;												
	}
}
//********************************************************************************************v